#include "view_time_2.h"
#include "view_time_2.inc"
#include "view_time_0.h"
#include "display_ctrl.h"
#include "platform_assert.h"
#include "lfs_file_manager_auto.h"
#include "rtc.h"
#include "datetime.h"
#include "blecom.h"
#include "battery_ctrl.h"
#include "sport_his.h"
#include "display_ctrl.h"
#include "display_interface_240x240.h"
#include "datetime.h"
#include "heart_rate_interface.h"
#include "font/num_font.h"
#include "font_mngr.h"
#include "view_common.h"
#include "app_trace.h"
#include "view_times.h"
#define LOG(fmt, ...) // app_trace_log(fmt "\r\n", ##__VA_ARGS__)
#if defined(TIME_2_SKIP)
#else
void view_time_2_display(void)
{
    if (disp_ctrl.loop_cnt == 0)
    {
        datetime_t UIdatetime = DateSync();
        disp_ctrl.com_data.i_temp[0] = ble_if_connected();
        disp_ctrl.com_data.i_temp[1] = battery_ctrl_get_level(battery_ctrl_get_percent());
        disp_ctrl.com_data.i_temp[2] = sport_get_present_step();
        disp_ctrl.com_data.i_temp[3] = UIdatetime.time.hour;
        disp_ctrl.com_data.i_temp[4] = UIdatetime.time.minute;
        disp_ctrl.com_data.i_temp[5] = get_present_week();
        disp_ctrl.com_data.i_temp[6] = UIdatetime.date.month;
        disp_ctrl.com_data.i_temp[7] = UIdatetime.date.day;
        disp_ctrl.com_data.i_temp[8] = if_time_hour_system_12();
        if (disp_ctrl.com_data.i_temp[8])
        {
            disp_ctrl.com_data.i_temp[8] += (disp_ctrl.com_data.i_temp[3] >= 12); // 1=am,2=pm
            disp_ctrl.com_data.i_temp[3] %= 12;
            if (disp_ctrl.com_data.i_temp[3] == 0)
            {
                disp_ctrl.com_data.i_temp[3] = 12;
            }
        }
        disp_ctrl.auto_refresh_time = 1000;
        disp_ctrl.com_data.i_temp[9] = get_present_week();
        disp_ctrl.com_data.i_temp[10] = battery_ctrl_if_charging();
    }
    int x = 0;
    int y = 0;
    _disp_show_flash_img(DISP_LFS_FILE_INDEX_0, x, y, FILE_IMG_time_2_base);

    x = 83;
    y = 10;
    if (disp_ctrl.com_data.i_temp[0])
    {
        disp_draw_user_image_ignore_color(x, y, RGB565_COLOR_BLACK, bmp_time_0_connect);
    }
    else
    {
        disp_draw_user_image_ignore_color(x, y, RGB565_COLOR_BLACK, bmp_time_0_disconnect);
    }

    x = 133;
    y = 12;
    disp_draw_user_image_ignore_color(x, y, RGB565_COLOR_BLACK, bmp_time_0_battery_back);
    if (disp_ctrl.com_data.i_temp[10])
    {
        disp_draw_user_image_ignore_color(x + 9, y + 0, RGB565_COLOR_BLACK, bmp_battery_charging);
    }
    else
    { // 2 2 7 2 12 2
        // 4x8 0x9cd3
        uint16_t color = 0x9cd3;
        if (disp_ctrl.com_data.i_temp[1] == 1)
        {
            color = 0x9020;
        }
        x += 2;
        y += 2;
        for (int i = 0; i < disp_ctrl.com_data.i_temp[1]; i++)
        {
            disp_draw_rect_color(x, y, x + 4 - 1, y + 8 - 1, color);
            x += 5;
        }
    }
    x = 70;
    y = 171;
    disp_draw_user_image_num(x, y, disp_ctrl.com_data.i_temp[2], 8, num_time_2_7x17_TAB);

    x = 89;
    y = 139;
    _disp_show_flash_img(DISP_LFS_FILE_INDEX_1, x, y, FILE_IMG_2010_week_mon_89_139 + disp_ctrl.com_data.i_temp[9] - 1);

    // 30 137 57
    x = 30;
    y = 137;
    disp_draw_user_image_num_with_digits(x, y, disp_ctrl.com_data.i_temp[6], 2, 9, num_time_2_7x17_TAB);
    x = 57;
    disp_draw_user_image_num_with_digits(x, y, disp_ctrl.com_data.i_temp[7], 2, 9, num_time_2_7x17_TAB);

    x = 29;
    y = 58;
    // _disp_show_flash_img(DISP_LFS_FILE_INDEX_2, x, y, FILE_IMG_2000_time_0 + disp_ctrl.com_data.i_temp[3] / 10);
    disp_draw_user_image_num_with_digits_filter_color(x, y, disp_ctrl.com_data.i_temp[3], 2, 44, num_tim_2_36x51_TAB);
    x = 73;
    // _disp_show_flash_img(DISP_LFS_FILE_INDEX_3, x, y, FILE_IMG_2000_time_0 + disp_ctrl.com_data.i_temp[3] % 10);
    x = 132;
    // _disp_show_flash_img(DISP_LFS_FILE_INDEX_4, x, y, FILE_IMG_2000_time_0 + disp_ctrl.com_data.i_temp[4] / 10);
    disp_draw_user_image_num_with_digits_filter_color(x, y, disp_ctrl.com_data.i_temp[4], 2, 44, num_tim_2_36x51_TAB);
    x = 175;
    // _disp_show_flash_img(DISP_LFS_FILE_INDEX_5, x, y, FILE_IMG_2000_time_0 + disp_ctrl.com_data.i_temp[4] % 10);
    // 68 101
    x = 117;
    y = 68;
    disp_draw_user_image(x, y, time_2_point);
    y = 101;
    disp_draw_user_image(x, y, time_2_point);
}
#endif
